package view.game
{
	//游戏斗地主
	
	import event.GlobalEvent;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Timer;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	import flash3.framework.Memory;
	import flash3.net.INetConnect;
	import flash3.net.NetFacade;
	
	import global.Define;
	import global.HtmlConnect;
	import global.Resource;
	
	import model.*;
	
	import mx.flash.UIMovieClip;
	
	import net.*;
	import net.html.IFrameFactory;
	
	import util.EffectCharAdd;
	import util.EffectShowCard;
	import util.HandleQueue;
	import util.ImageNumber;
	import util.MovieClipButton;
	import util.RandomUtil;
	
	import view.layer.L;
	import view.plugin.*;
	
	import vo.*;
	import vo.GamePlayer;
	import vo.GameType;
	import vo.UserStatus;

	public class GameDdzLords extends GameBase
	{
		public var ready:Array = [];
		public var info:Array = [];
		public var out:Array = [];
		public var tips:Array = [];
		public var score:Array = [];
		public var avatar:Array = [];
		public var cardtype:Array = [];
		public var btnStart:SimpleButton;
		public var btnBrightStart:SimpleButton;
		public var btnRestart:SimpleButton;
		public var btnChangeTable:SimpleButton;
		public var btnOutCard:*;
		public var btnTips:*;
		public var btnPass:*;
		public var btnTrustee:*;
		public var btnCannelTrustee:SimpleButton;
		public var btnSort:SimpleButton;
		private var mcTrustee:MovieClip;
		private var mcShunzi:MovieClip;
		private var mcShuangShun:MovieClip;
		private var mcBomb:MovieClip;
		private var mcStart:MovieClip;
		private var imgLand:MovieClip;
		private var timerCount:EffectCharAdd;
		private var cardControl:Array = [];
		private var outControl:Array = [];
		private var backControl:CardControl;
		private var main:MovieClip;
		private var effectShowCard:Array = [];
		private var chatBubble:Array = [];
		private var cardCount:Array = [];
		private var alarm:Array = [];
		private var baseScore:BaseScore;
		private var doubleScore:BaseScore;
		
		private var btnCallLand:SimpleButton;
		private var btnNotCallLand:SimpleButton;
		private var btnSnatchLand:SimpleButton;
		private var btnNotSnatchLand:SimpleButton;
		private var btnDoubleScore:*;
		private var btnNotDoubleScore:*;
		private var btnBrightCard:SimpleButton;
		private var btnNotBrightCard:SimpleButton;
		private var btnChest:MovieClip;
		private var btnRank:SimpleButton;
		
		private var STATE_FREE:uint = 0;
		private var STATE_READY:uint = 1;
		private var STATE_SENDCARD:uint = 2;
		private var STATE_CALLLAND:uint = 3;
		private var STATE_SNATCHLAND:uint = 4;
		private var STATE_BRIGHTCARD:uint = 5;
		private var STATE_DOUBLESCORE:uint = 6;
		private var STATE_GAME:uint = 7;
		private var STATE_GAMEEND:uint = 8;
		private var STATE_WAIT:uint = 9;
		
		private var handleQueue:HandleQueue;
		
		private var curState:uint = 0;
		
		private var tickCount:uint = 0;
		
		private var cardBitmapData:CardBitmapData = null;
		
		private var gameResult:GameResult;
		private var meIsBright:Boolean = false;
		private var isAutoPlay:Boolean = false;;
		
		private static const FRAME_ONE:uint = 1;
		private static const FRAME_TWO:uint = 2;
		private static const FRAME_TRHEE:uint = 3;
		private static const FRAME_NOCALL:uint = 4;
		private static const FRAME_NOOUT:uint = 5;
		private static const FRAME_DOUBLE:uint = 6;
		private static const FRAME_NOGRAB:uint = 7;
		private static const FRAME_GRABLAND:uint = 8;
		private static const FRAME_BRIGHT:uint = 9;
		private static const FRAME_CALLLAND:uint = 10;
		private static const FRAME_NOBRIGHT:uint = 11;
		private static const FRAME_NODOUBLE:uint = 12;
		
		private var isExitGame:Boolean = false;
		private var isMustEixt:Boolean = false;
		private var passCount:uint = 0;
		private var analyseResult:AnalyseResult = new AnalyseResult();
		
		private var curCardType:uint;
		private var curTipsIndex:int = -1;
		private var tipsList:Array = [];
		
		private var roomInfo:RoomInfo = null;
		
		public function GameDdzLords()
		{
			super();
			addChild(Resource.i.getMovieClip("ddzBg","DdzBg"));
			addChild(main = Resource.i.getMovieClip("ddzlords","DdzLords"));
			ready.push(main.mcReady01, main.mcReady02, main.mcReady03);
			info.push(main.mcInfo01, main.mcInfo02, main.mcInfo03);
			tips.push(main.mcJiaofen01, main.mcJiaofen02, main.mcJiaofen03);
			score.push(main.score1,main.score2,main.score3);
			
			var btns:Array = [{btn:main.btn1,type:GameLogic.CT_SINGLE_LINE},
				{btn:main.btn2,type:GameLogic.CT_DOUBLE_LINE},
				{btn:main.btn3,type:GameLogic.CT_MISSILE_CARD},
				{btn:main.btn4,type:GameLogic.CT_BOMB_CARD},
				{btn:main.btn5,type:GameLogic.CT_THREE_LINE},
				{btn:main.btn6,type:GameLogic.CT_DOUBLE},
				{btn:main.btn7,type:GameLogic.CT_THREE}];
			var i:uint = 0;
			var mcb:MovieClipButton;
			for(i == 0; i < 7; i++)
			{
				mcb = new MovieClipButton(btns[i].btn);
				cardtype.push({btn:mcb, type:btns[i].type});
			}
			btnStart = main.btnStart;
			btnBrightStart = main.btnBrightStart;
			btnRestart = main.btnRestart;
			btnChangeTable = main.btnChangeTable;
			btnOutCard = new MovieClipButton(main.btnOutCard);
			btnTips = new MovieClipButton(main.btnTips);
			btnPass = new MovieClipButton(main.btnPass);
			out.push(btnOutCard, btnTips, btnPass);
			btnCallLand = main.btnCallLand;
			btnNotCallLand = main.btnNotCallLand;
			btnSnatchLand = main.btnSnatchLand;
			btnNotSnatchLand = main.btnNotSnatchLand;
			btnDoubleScore = new MovieClipButton(main.btnDoubleScore);
			btnNotDoubleScore = new MovieClipButton(main.btnNotDoubleScore);
			btnBrightCard = main.btnBrightCard;
			btnNotBrightCard = main.btnNotBrightCard;
			btnBrightStart = main.btnBrightStart;
			btnTrustee = new MovieClipButton(main.btnTrustee);
			btnCannelTrustee = main.btnCannelTrustee;
			btnChest = main.btnChest;
			btnRank = main.btnRank;
			btnSort = main.btnSort;
			mcTrustee = main.mcTrustee;
			mcShunzi = Resource.i.getMovieClip("anim", "ShunZi");
			mcShuangShun = Resource.i.getMovieClip("anim", "ShuangShun");;
			mcBomb = Resource.i.getMovieClip("anim", "Bomb");
			mcStart = Resource.i.getMovieClip("anim", "Start");
			mcShunzi.x = 416; mcShunzi.y = 284;
			mcShuangShun.x = 416; mcShuangShun.y = 284;
			mcBomb.x = 416; mcBomb.y = 284;
			mcStart.x = 416; mcStart.y = 347;
			mcStart.mouseEnabled = false;
			mcShunzi.mouseEnabled = false;
			mcShuangShun.mouseEnabled = false;
			mcBomb.mouseEnabled = false;
			btnChest.buttonMode = true;
			imgLand = main.imgLand;
			mcTrustee.gotoAndStop(1);
			baseScore = new BaseScore(main.baseScore, Resource.i.getBitmapData("number04"));
			doubleScore = new BaseScore(main.doubleScore, Resource.i.getBitmapData("number04"));
			for(i = 0; i < Define.GAME_PLAYER; i++)
			{
				effectShowCard[i] = new EffectShowCard(150);
				info[i].txtName.mouseEnabled = false;
				(info[i] as MovieClip).mouseEnabled = false;
			}
			
			timerCount = new EffectCharAdd(null, 1000, 1, 30, 0, false);
			
			var tmpBmp:Bitmap = Resource.i.getBitmap("cardbig");
			cardBitmapData = new CardBitmapData(tmpBmp);
			
			var orix:Number = 0;
			var oriy:Number = -40;
			var point1:Array = [new Point(orix+416,oriy+566),new Point(orix+800,oriy+200),new Point(orix+20,oriy+200),new Point(main.width/2+3,oriy+100)];
			var point2:Array = [new Point(orix+416,oriy+445), new Point(orix+720, oriy+305), new Point(orix+112, oriy+305)];
			var controls:CardControl = null;
			backControl = new CardControl(false);
			backControl.setBitmapData(cardBitmapData, 53, 70);
			backControl.setDirection(true);
			backControl.setBright(false);
			backControl.SetCardSpace(60, 0, 20);
			backControl.setBenchmarkPos(point1[3], CardControl.enXCenter, CardControl.enYCenter);
			main.addChild(backControl);
			for(i = 0; i < 3; i++)
			{
				controls = new CardControl(i==0);
				controls.setBitmapData(cardBitmapData, i==0?75:42, i==0?102:58);
				controls.setBright(i == 0);
				controls.setDirection(true);
				controls.SetCardSpace(i==0?24:12, 20, 16 );
				if(i == 0)
					controls.setBenchmarkPos(point1[i], CardControl.enXCenter, CardControl.enYCenter);
				else if(i == 1)
					controls.setBenchmarkPos(point1[i], CardControl.enXRight, CardControl.enYCenter);
				else 
					controls.setBenchmarkPos(point1[i], CardControl.enXLeft, CardControl.enYCenter);
				cardControl[i] = controls;
				main.addChild(controls);
				
				controls = new CardControl(false);
				controls.setBitmapData(cardBitmapData, 75, 102);
				controls.setBright(true);
				controls.setDirection(true);
				controls.SetCardSpace( 21, 20, 16 );
				if(i == 0)
					controls.setBenchmarkPos(point2[i], CardControl.enXCenter, CardControl.enYCenter);
				else if(i == 1)
					controls.setBenchmarkPos(point2[i], CardControl.enXRight, CardControl.enYCenter);
				else
					controls.setBenchmarkPos(point2[i], CardControl.enXLeft, CardControl.enYCenter);
				outControl[i] = controls;
				main.addChild(controls);
			}
			
			gameResult = new GameResult(Resource.i.getMovieClip("gameResult", "GameResult"));
			main.addChild(btnStart);
			main.addChild(btnBrightStart);
			main.addChild(main.btnCannelTrustee);
			
			var chatButtlePos:Array = [new Point(orix+586,380),new Point(orix+586,215),new Point(orix+93,215)];
			var playerInfoPos:Array = [new Point(-180,-26),new Point(-180,-26),new Point(60,-26)];
			var userImagePos:Array = [new Point(748,394),new Point(748,208),new Point(34,208)];
			var bubbleClass:Array = ["ChatBubbleRightDown","ChatBubbleRightUp","ChatBubbleLeftUp"];
			var bubbleTxtPos:Array = [new Point(5, 8),new Point(12, 8),new Point(30, 8)];	
			var cardNumber:ImageNumber = null;
			for(i = 0; i < 3; i++)
			{
				chatBubble[i] = new GameChat(Resource.i.getMovieClip("common", bubbleClass[i]), bubbleTxtPos[i]);
				chatBubble[i].x = chatButtlePos[i].x;
				chatBubble[i].y = chatButtlePos[i].y;
				showDisplayObject(chatBubble[i], false);
				if(i != 0)
				{
					cardNumber = new ImageNumber(Resource.i.getBitmapData("number01"));
					cardNumber.x = i != 1 ? 25 : 762;
					cardNumber.y = 136;
					cardNumber.scaleX = 0.7;
					cardNumber.scaleY = 0.9;
					cardNumber.signVisible = false;
					cardCount[i] = cardNumber;
					alarm[i] = i==1 ? main.alarm2 : main.alarm3;
				}
				
				var userImage:UserImage = new UserImage();
				userImage.x = userImagePos[i].x;userImage.y = userImagePos[i].y;
				avatar[i] = userImage;
				if(i != 0)
					main.addChild(cardNumber);
				main.addChild(chatBubble[i]);
				main.addChild(ready[i]);
				main.addChild(info[i]);
				main.addChild(userImage);
			}
			main.addChild(alarm[1]);
			main.addChild(alarm[2]);
			main.addChild(baseScore);
			main.addChild(doubleScore);
			
			handleQueue = new HandleQueue();
			main.direction.gotoAndStop(0);
			
			main.addChild(mcStart);
			main.addChild(mcShunzi);
			main.addChild(mcShuangShun);
			main.addChild(mcBomb);
			
			roomInfo = new RoomInfo();
			main.addChild(roomInfo);
			roomInfo.x = 12; roomInfo.y = 620;
			
			TipsPanel.i.add(btnTrustee, "托管后不出牌，除非只剩最后一张牌", new Point(675,598));
		}
		override public function enter():void
		{
			super.enter();
			initialize();
			btnStart.addEventListener(MouseEvent.CLICK, onClickBtnStart);
			btnBrightStart.addEventListener(MouseEvent.CLICK, onClickBtnBrightStart);
			btnOutCard.addEventListener(MouseEvent.CLICK, onClickBtnOutCard);
			btnTips.addEventListener(MouseEvent.CLICK, onClickBtnTips);
			btnPass.addEventListener(MouseEvent.CLICK, onClickBtnPass);
			btnCallLand.addEventListener(MouseEvent.CLICK, onClickBtnCallLand);
			btnNotCallLand.addEventListener(MouseEvent.CLICK, onClickBtnNotCallLand);
			btnSnatchLand.addEventListener(MouseEvent.CLICK, onClickBtnSnatchLand);
			btnNotSnatchLand.addEventListener(MouseEvent.CLICK, onClickBtnNotSnatchLand);
			btnDoubleScore.addEventListener(MouseEvent.CLICK, onClickBtnDoubleScore);
			btnNotDoubleScore.addEventListener(MouseEvent.CLICK, onClickBtnNotDoubleScore);
			btnBrightCard.addEventListener(MouseEvent.CLICK, onClickBtnBrightCard);
			btnNotBrightCard.addEventListener(MouseEvent.CLICK, onClickBtnNotBrightCard);
			GlobalPanel.i.addEventListener(GlobalPanel.CLICK_LEAVE, onClickBtnLeaved);
			btnTrustee.addEventListener(MouseEvent.CLICK, onClickBtnTrustee);
			btnCannelTrustee.addEventListener(MouseEvent.CLICK, onClickBtnCannelTrustee);
			btnChest.addEventListener(MouseEvent.CLICK, onClickBtnChest);
			btnRank.addEventListener(MouseEvent.CLICK, onClickBtnRank);
			btnSort.addEventListener(MouseEvent.CLICK, onClickBtnSort);
			timerCount.addEventListener(Event.COMPLETE,onTimerCountComplete);
			timerCount.addEventListener(EffectCharAdd.TIMER_COUNT, onTimerCount);
			effectShowCard[0].addEventListener(EffectShowCard.SHOW_CARD, onEffectShowCard);

			var i:uint = 0;
			for(i = 0; i < cardtype.length; i++)
			{
				cardtype[i].btn.addEventListener(MouseEvent.CLICK, onClickBtnCardType);
				cardtype[i].btn.visible = false;
			}
			updateUserStatus(); 
			main.timerCount.gotoAndStop(0);
			showDisplayObject(info[0], true);
			showDisplayObject(btnStart, true);
			showDisplayObject(btnBrightStart, true);
			showDisplayObject(btnTrustee, true);
			main.addChild(btnStart);
			main.addChild(btnBrightStart);
			btnStart.y = 389;
			btnBrightStart.y = 389;
			btnTrustee.enable = false;
			curState = STATE_FREE;
			showTimer(0, GameConst.TIMER_FREE, 1);
			isAutoPlay = false;
			meIsBright = false;
			gameInit();
			roomInfo.updateData();
			
			ChatPanel.i.init();
			ChatPanel.i.show(true);
			OutputPanel.i.addEventListener(GlobalEvent.GLOBAL_USERCHAT, onUserChat);
			GlobalPanel.i.updateInfo();
			OutputPanel.i.clear();
			OutputPanel.i.show(true);
			
			var gameServer:GameServer = GameModel.i.gameServer;
			var isRally:Boolean = gameServer.isType(GameServer.GAME_GENRE_RALLY);
			RallyMessagePanle.i.show(isRally);
			
			for(i = 0; i < Define.GAME_PLAYER; i++)
				score[i].icon.gotoAndStop(isRally ? 2 : 1);
			
//			chestTest();
		}
		private function chestTest():void
		{
			var rewardMessage:RewardMessage = new RewardMessage();
			rewardMessage.szMsg = "恭喜你获得100金币！";
			RewardModel.i.add(rewardMessage);
			rewardMessage = new RewardMessage();
			rewardMessage.szMsg = "恭喜你获得200金币！";
			RewardModel.i.add(rewardMessage);
			handleQueue.add({delay:4000, handle:netNotifyRewardMessage});
			handleQueue.reset();
			handleQueue.start();
		}
		override public function leave():void
		{
			super.leave();
			showDisplayObject(btnStart, false);
			showDisplayObject(btnBrightStart, false);
			btnStart.removeEventListener(MouseEvent.CLICK, onClickBtnStart);
			btnOutCard.removeEventListener(MouseEvent.CLICK, onClickBtnOutCard);
			btnTips.removeEventListener(MouseEvent.CLICK, onClickBtnTips);
			btnPass.removeEventListener(MouseEvent.CLICK, onClickBtnPass);
			btnCallLand.removeEventListener(MouseEvent.CLICK, onClickBtnCallLand);
			btnNotCallLand.removeEventListener(MouseEvent.CLICK, onClickBtnNotCallLand);
			btnSnatchLand.removeEventListener(MouseEvent.CLICK, onClickBtnSnatchLand);
			btnNotSnatchLand.removeEventListener(MouseEvent.CLICK, onClickBtnNotSnatchLand);
			btnDoubleScore.removeEventListener(MouseEvent.CLICK, onClickBtnDoubleScore);
			btnNotDoubleScore.removeEventListener(MouseEvent.CLICK, onClickBtnNotDoubleScore);
			btnBrightCard.removeEventListener(MouseEvent.CLICK, onClickBtnBrightCard);
			btnNotBrightCard.removeEventListener(MouseEvent.CLICK, onClickBtnNotBrightCard);
			GlobalPanel.i.removeEventListener(GlobalPanel.CLICK_LEAVE, onClickBtnLeaved);
			btnTrustee.removeEventListener(MouseEvent.CLICK, onClickBtnTrustee);
			btnCannelTrustee.removeEventListener(MouseEvent.CLICK, onClickBtnCannelTrustee);
			btnChest.removeEventListener(MouseEvent.CLICK, onClickBtnChest);
			btnRank.removeEventListener(MouseEvent.CLICK, onClickBtnRank);
			btnSort.removeEventListener(MouseEvent.CLICK, onClickBtnSort);
			timerCount.removeEventListener(Event.COMPLETE,onTimerCountComplete);
			for(var i:uint = 0; i < Define.GAME_PLAYER; i++)
				(effectShowCard[i] as EffectShowCard).removeEventListener(Event.COMPLETE, onSendCardComplete);
			for(i = 0; i < cardtype.length; i++)
				cardtype[i].btn.removeEventListener(MouseEvent.CLICK, onClickBtnCardType);
			ChatPanel.i.show(false);
			OutputPanel.i.show(false);
			OutputPanel.i.removeEventListener(GlobalEvent.GLOBAL_USERCHAT, onUserChat);
			timerCount.removeEventListener(EffectCharAdd.TIMER_COUNT, onTimerCount);
			effectShowCard[0].removeEventListener(EffectShowCard.SHOW_CARD, onEffectShowCard);
			var gameServer:GameServer = GameModel.i.gameServer;
			if(gameServer.isType(GameServer.GAME_GENRE_RALLY))
			{
				RallyMessagePanle.i.show(false);
			}
			ExitPanel.i.removeEventListener(ExitPanel.OK, onExitPanelOK);
			ExitPanel.i.removeEventListener(ExitPanel.CANSEL, onExitPanelClose);
			GameModel.i.tableInfo = null;
		}
		override public function update(lastTime:int):void
		{
		}
		private function initialize():void
		{
			showDisplayObject(ready, false);
			showDisplayObject(tips, false);
			showDisplayObject(info, false);
			showDisplayObject(score, false);
			showDisplayObject(btnOutCard, false);
			showDisplayObject(btnTips, false);
			showDisplayObject(btnPass, false);
			showDisplayObject(btnCannelTrustee, false);
			showDisplayObject(mcTrustee, false);
			showDisplayObject(mcShunzi, false);
			showDisplayObject(mcShuangShun, false);
			showDisplayObject(mcBomb, false);
			showDisplayObject(mcStart, false);
			showDisplayObject(imgLand, false);
			showDisplayObject(btnStart, false);
			showDisplayObject(btnBrightStart, false);
			showDisplayObject(btnRestart, false);
			showDisplayObject(btnChangeTable, false);
			showDisplayObject(btnCallLand, false);
			showDisplayObject(btnNotCallLand, false);
			showDisplayObject(btnSnatchLand, false);
			showDisplayObject(btnNotSnatchLand, false);
			showDisplayObject(btnDoubleScore, false);
			showDisplayObject(btnNotDoubleScore, false);
			showDisplayObject(btnBrightCard, false);
			showDisplayObject(btnNotBrightCard, false);
			showDisplayObject(backControl, false);
			showDisplayObject(btnNotBrightCard, false);
			showDisplayObject(btnNotBrightCard, false);
			showDisplayObject(alarm, false);
			showDisplayObject(baseScore, false);
			showDisplayObject(doubleScore, false);
			showDisplayObject(cardCount, false);
			showDisplayObject(btnChest, false);
			gameResult.show(false);
			
//			gameResult.updateData();
//			gameResult.show(true);
//			showDisplayObject(btnStart, true);
//			showDisplayObject(btnBrightStart, true);
//			btnStart.y = 470;
//			btnBrightStart.y = 470;
			
			for(var i:uint = 0; i < Define.GAME_PLAYER; i++)
			{
				showDisplayObject(cardControl[i], false);
				showDisplayObject(outControl[i], false);
				showDisplayObject(chatBubble[i], false);
				showDisplayObject(avatar[i], false);
			}
		}
//=================================================================================================================================
		
		private function onClickBtnLeaved(evt:MouseEvent):void
		{
			var gameServer:GameServer = GameModel.i.gameServer;
			if(gameServer.isType(GameServer.GAME_GENRE_RALLY))
			{
				if(curState == STATE_FREE || curState == STATE_READY || curState == STATE_WAIT)
				{
					ExitPanel.i.text = ExitPanel.getStr1();
					isMustEixt = false;
				}
				else
				{
					ExitPanel.i.text = ExitPanel.getStr2();
					isMustEixt = true;
				}
				ExitPanel.i.show(true);
				ExitPanel.i.addEventListener(ExitPanel.OK, onExitPanelOK);
				ExitPanel.i.addEventListener(ExitPanel.CANSEL, onExitPanelClose);
			}
			else
			{
				if(curState != STATE_FREE && curState != STATE_READY)
				{
					MessageBox.i.show(MessageBox.BTN_OK | MessageBox.BTN_CANSEL, "确定要离开游戏吗?", onLeaveGameHandle);
					isMustEixt = true;
				}
				else
				{
					isMustEixt = false;
					onLeaveGameHandle();
				}
					
			}
		}
		private function onExitPanelOK(evt:Event):void
		{
			ExitPanel.i.removeEventListener(ExitPanel.OK, onExitPanelOK);
			ExitPanel.i.removeEventListener(ExitPanel.CANSEL, onExitPanelClose);
			onLeaveGameHandle();
		}
		private function onExitPanelClose(evt:Event):void
		{
			ExitPanel.i.show(false)
			ExitPanel.i.removeEventListener(ExitPanel.OK, onExitPanelOK);
			ExitPanel.i.removeEventListener(ExitPanel.CANSEL, onExitPanelClose);
		}
		private function onClickBtnTrustee(evt:MouseEvent):void
		{
			onUserTrusteeHandle(true);
			updateTrustee();
		}
		private function onClickBtnCannelTrustee(evt:MouseEvent):void
		{
			onUserTrusteeHandle(false);
		}
		private var chestIndex:Number = 0;
		private var rankIndex:Number = 0;
		private var isClickChest:Boolean = false;
		private function onClickBtnChest(evt:MouseEvent):void
		{
			if(isClickChest) return;
			isClickChest = true;
			btnChest.gotoAndPlay(24);
			rankIndex = setTimeout(function ():void{clearTimeout(rankIndex);showDisplayObject(btnChest, false);}, 1500);
			startPopup();
		}
		private function startPopup():void
		{
			var rewardMessage:RewardMessage = RewardModel.i.pop() as RewardMessage;
			if(rewardMessage)
			{
				FloatText.i.start(rewardMessage.szMsg);
				chestIndex = setTimeout(function ():void{clearTimeout(chestIndex);startPopup();}, 1500);
			}
		}
		private function onClickBtnRank(evt:MouseEvent):void
		{
			var gameServer:GameServer = GameModel.i.gameServer;
			HtmlConnect.showRankPanel({stationid:gameServer.wStationID,
				kindid:gameServer.wKindID,
				serverid:gameServer.wServerID,
				userid:MeInfoModel.i.getMeUserID()});
		}
		private function onClickBtnSort(evt:MouseEvent):void
		{
			var meCardControl:CardControl = cardControl[getMeViewChairID()];
			var sortType:uint = meCardControl.getSortType();
			if(sortType == GameLogic.ST_COUNT)
				sortType = GameLogic.ST_ORDER;
			else
				sortType = GameLogic.ST_COUNT;
			meCardControl.sortCard(sortType);
		}
		private function onClickBtnStart(evt1:MouseEvent):void
		{
			showDisplayObject(ready[0], true);
			onGameStartHandle();
		}
		private function onClickBtnBrightStart(evt1:MouseEvent):void
		{
			onGameStartHandle();
			meIsBright = true;
			var chairID:int = getMeChairID();
			if(chairID != -1)
				GameModel.i.gamePlayers[chairID].isBright = true;
			NetFacade.i.send(GameGroup.MDM_GF_GAME,GameGroup.SUB_C_BRIGHT_START);
		}
		private function onClickBtnBrightCard(evt1:MouseEvent):void
		{
			var brightCardTime:int = 255;
			if(curState == STATE_FREE)
				brightCardTime = GameConst.BRIGHT_START_TIME;
			else if(curState == STATE_SENDCARD)
				brightCardTime = GameConst.BRIGHT_CARD_TIME;
			if(curState == STATE_BRIGHTCARD)
				brightCardTime = GameConst.BRIGHT_BRIGHT_TIME;
			onBrightCard(brightCardTime);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnNotBrightCard(evt1:MouseEvent):void
		{
			onBrightCard(255);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnOutCard(evt1:MouseEvent):void
		{
			var meChairID:uint = getMeChairID();
			var viewChairID:uint = switchViewChairID(meChairID);
			var outCardData:Array = (cardControl[viewChairID] as CardControl).getShootCard();
			if(GameLogic.i.CompareCard(GameModel.i.outCardData, outCardData))
			{
				this.showDisplayObject(out, false);
				GameModel.i.outCardData = outCardData;
				NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_OUT_CART);
				updateOutCardControl(viewChairID, outCardData);
				handleQueue.clear();
				showCardType();
				killTimer();
			}
			else
			{
				FloatText.i.start("您选择的牌不符合规则！");
			}
			onUserTrusteeHandle(false);
		}
		private function onClickBtnTips(evt1:MouseEvent):void
		{
			onUserTrusteeHandle(false);
			var wMeChairID:uint = this.switchViewChairID(getMeChairID());
			if(tipsList && tipsList.length > 0)
			{
				if(curTipsIndex + 1 >= tipsList.length)
					curTipsIndex = 0;
				else
					++curTipsIndex;
				cardControl[wMeChairID].shootCardByData(tipsList[curTipsIndex]);
			}
			else
			{
				onPassCardHandle();
			}
		}
		private function onClickBtnPass(evt1:MouseEvent):void
		{
			if(this.isAutoPlay)
				handleQueue.clear();
			this.onPassCardHandle();
			onUserTrusteeHandle(false);
		}
		private function onClickBtnCardType(evt:MouseEvent):void
		{
			for(var i:uint = 0; i < cardtype.length; i++)
			{
				if(evt.target == cardtype[i].btn)
				{
					var outCardData:Array = cardtype[i].result;
					if(outCardData.length > 0)
					{
						var index:int = cardtype[i].index >= outCardData.length-1 ? 0 : cardtype[i].index+1;
						cardtype[i].index = index;
						cardControl[getMeViewChairID()].shootCardByData(outCardData[cardtype[i].index]);
					}
					break;
				}
				else
				{
					cardtype[i].index = -1;
				}
			}
		}
		private function onClickBtnCallLand(evt1:MouseEvent):void
		{
			onLandScoreHandle(GameConst.ACTION_CALLLAND);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnNotCallLand(evt1:MouseEvent):void
		{
			onLandScoreHandle(GameConst.ACTION_PASS);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnSnatchLand(evt1:MouseEvent):void
		{
			onLandScoreHandle(GameConst.ACTION_GRABLAND);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnNotSnatchLand(evt1:MouseEvent):void
		{
			onLandScoreHandle(GameConst.ACTION_PASS);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnDoubleScore(evt1:MouseEvent):void
		{
			onDoubleScore(true);
			onUserTrusteeHandle(false);
		}
		private function onClickBtnNotDoubleScore(evt1:MouseEvent):void
		{
			onDoubleScore(false);
			onUserTrusteeHandle(false);
		}
		
//=================================================================================================================================
		
		private function updateUserStatus():void
		{
			var userInfo:UserInfo = null;
			var userStatus:UserStatus = null;
			var userScore:UserScore = null;
			var tableInfo:TableInfo = GameModel.i.tableInfo;
			var gameServer:GameServer = GameModel.i.gameServer;
			var isRally:Boolean = gameServer.isType(GameServer.GAME_GENRE_RALLY);
			for(var i:uint = 0; i < Define.GAME_PLAYER; i++)
			{
				userStatus = tableInfo ? tableInfo.userStatus[i] : null;
				var chairID:uint = tableInfo ? switchViewChairID(i) : i;
				if(userStatus)
				{
					if(userStatus.dwUserID == MeInfoModel.i.userInfo.dwUserID)
					{
						roomInfo.updateData();
					}
					if(userStatus.cbUserStatus == UserStatus.STATE_FREE)
					{
						showDisplayObject(info[chairID], false);
						showDisplayObject(score[chairID], false);
						showDisplayObject(ready[chairID], false);
						showDisplayObject(tips[chairID], false);
						showDisplayObject(avatar[chairID], false);
						if(cardCount[chairID])
							showDisplayObject(cardCount[chairID], false);
						avatar[chairID].reset();
					}
					else if(userStatus.cbUserStatus == UserStatus.STATE_SIT)
					{
						userInfo = UserInfoModel.i.value(userStatus.dwUserID);
						userScore = UserScoreModel.i.value(userStatus.dwUserID);
						if(userInfo)
						{
							showDisplayObject(info[chairID], true);
							showDisplayObject(score[chairID], true);
							info[chairID].txtName.text = userInfo.szAccounts;
							showDisplayObject(avatar[chairID], true);
							avatar[chairID].loader(userInfo);
							score[chairID].value.text = userScore.lScore;
						}
					}
					else if(userStatus.cbUserStatus == UserStatus.STATE_READY)
					{
						userInfo = UserInfoModel.i.value(userStatus.dwUserID);
						userScore = UserScoreModel.i.value(userStatus.dwUserID);
						if(userInfo)
						{
							showDisplayObject(info[chairID], true);
							showDisplayObject(score[chairID], true);
							if(GameModel.i.gamePlayers[userStatus.wChairID].isBright)
							{
								tips[chairID].gotoAndStop(FRAME_BRIGHT);
							}
							showDisplayObject(tips[chairID], GameModel.i.gamePlayers[userStatus.wChairID].isBright);
							showDisplayObject(ready[chairID], !GameModel.i.gamePlayers[userStatus.wChairID].isBright);
							info[chairID].txtName.text = userInfo.szAccounts;
							showDisplayObject(avatar[chairID], true);
							showDisplayObject(outControl[chairID], false);
							avatar[chairID].loader(userInfo);
							score[chairID].value.text = userScore.lScore;
						}
					}
					
				}
				else
				{
					showDisplayObject(info[chairID], false);
					showDisplayObject(score[chairID], false);
					showDisplayObject(ready[chairID], false);
					showDisplayObject(tips[chairID], false);
					showDisplayObject(avatar[chairID], false);
					if(cardCount[chairID])
						showDisplayObject(cardCount[chairID], false);
					avatar[chairID].reset();
					
					var effectCard:EffectShowCard = effectShowCard[chairID] as EffectShowCard;
					effectCard.removeEventListener(Event.COMPLETE, onSendCardComplete);
					effectShowCard[0].removeEventListener(EffectShowCard.SHOW_CARD, onEffectShowCard);
				}
			}
		}
		private function updateTrustee():void
		{
			if(!isAutoPlay) return;
			
			switch(curState)
			{
				case STATE_CALLLAND: this.trusteeCallLand(); break;
				case STATE_SNATCHLAND: trusteeGrabLand(); break;
				case STATE_BRIGHTCARD: trusteeBrightCard(); break;
				case STATE_DOUBLESCORE: trusteeDoubleScore(); break;
				case STATE_GAME: trusteeOutCard(); break;
				default: break;
			}
		}
		public function updateCardCount():void
		{
			var cardCounts:Number = cardControl[1].getCardCount();
			cardCount[1].value = cardCounts;
			cardCount[1].x = cardCounts >= 10 ? 778 : 780;
			cardCounts = cardControl[2].getCardCount();
			cardCount[2].value = cardCounts;
			cardCount[2].x = cardCounts >= 10 ? 39 : 40;
		}
		private function switchViewChairID(chairID:uint):int
		{
			var meChairID:uint = getMeChairID();
			
			if(meChairID == chairID)
				return 0;
			
			if(meChairID == 0)
			{
				return chairID == 1 ? 1 : 2;
			}
			else if(meChairID == 1)
			{
				return chairID == 2 ? 1 : 2;
			}
			else
			{
				return chairID == 0 ? 1 : 2;
			}
		}
		private function getMeChairID():int
		{
			return MeInfoModel.i.userStatus.wChairID;
		}
		public function updateLandImage(land:uint):void
		{
			var imgLandPos:Array = [new Point(757, 370),new Point(757, 183),new Point(41, 183)];
			var viewChairID:uint = switchViewChairID(land);
			imgLand.x = imgLandPos[viewChairID].x;
			imgLand.y = imgLandPos[viewChairID].y;
			showDisplayObject(imgLand, true);
		}
		private function isLookonMode():Boolean
		{
			return false;
		}
		private function showTimer(chairID:uint, max:uint, min:uint):void
		{
			showDisplayObject(main.direction, true);
			showDisplayObject(main.timerCount, true);
			main.timerCount.gotoAndStop(31 - max);
			playDiection(chairID);
			timerCount.setRangle(max, min);
			timerCount.reset();
			timerCount.start();
		}
		private function playDiection(chairID:uint):void
		{
			var frame:uint = 0;
			if(chairID == 1)frame = 1;
			else if(chairID == 2)frame = 10;
			else if(chairID == 0)frame = 20;
			main.direction.gotoAndPlay(frame);
		}
		private function killTimer():void
		{
			showDisplayObject(main.direction, false);
			showDisplayObject(main.timerCount, false);
			timerCount.stop();
		}
		private function updateOutCardControl(chairID:uint, cardData:Array):void
		{
			outControl[chairID].SetCardData(cardData);
			cardControl[chairID].removeCard(cardData);
		}
		private function setBrightTime(time:Number):void
		{
			GameModel.i.curBrightTime = time;
			showDisplayObject(doubleScore);
			doubleScore.value = time;
		}
		private function getMeViewChairID():uint
		{
			return switchViewChairID(getMeChairID());
		}
		protected function showReady(chairId:uint, visible:Boolean):void
		{
			showDisplayObject(ready[chairId], visible);
		}
		protected function getNextChairId(curChairId:uint):uint
		{
			if(curChairId == 0 || curChairId == 1)
				return ++curChairId;
			return 0;
		}
		
//=================================================================================================================================
		
		private function onUserChat(evt:GlobalEvent):void
		{
			onUserChatHandle(evt.data as UserChat);
		}
		private function onEffectShowCard(evt:Event):void
		{
			playSound("DISPATCH_CARD");
		}
		private function onLackPetrolAddPrtrol(evt:GlobalEvent):void
		{
			var supplyItem:SupplyItem = SupplyItemModel.i.value(evt.data);
			if(MeInfoModel.i.userScore.lGoldScore >= supplyItem.gold)
			{
				NetFacade.i.send(UserGroup.MDM_GR_USER, UserGroup.SUB_GR_USER_SUPPLY_APPLY, evt.data);
			}
			else
			{
				FloatText.i.start("余额不足！");
			}
		}
		private function onSendCardComplete(evt:Event):void
		{
			if(tickCount >= 2)
			{
				curState = STATE_CALLLAND;
				updateCardCount();
				var viewChairID:uint = switchViewChairID(GameModel.i.curUser);
				showTimer(viewChairID, GameConst.TIMER_CALLLAND, 1);
				showDisplayObject(btnBrightCard, false);
				showDisplayObject(tips[viewChairID], false);
				if(this.getMeChairID() == GameModel.i.curUser)
				{
					this.showDisplayObject(btnCallLand, true);
					this.showDisplayObject(btnNotCallLand, true);
					updateTrustee();
				}
				playSound("GAME_START");
				curState = STATE_CALLLAND;
				for(var i:uint = 0; i < Define.GAME_PLAYER; i++)
				{
					var chairViewID:uint = switchViewChairID(i);
					if(chairViewID != this.getMeViewChairID())
					{
						if(cardControl[chairViewID].isBright != GameModel.i.gamePlayers[i].isBright)
						{
							if(chairViewID == 2)
								cardControl[chairViewID].setReverse(false);
							cardControl[chairViewID].setBright(GameModel.i.gamePlayers[i].isBright);
							if(chairViewID == 2)
								cardControl[chairViewID].setReverse(!GameModel.i.gamePlayers[i].isBright);
							cardControl[chairViewID].SetCardData(GameModel.i.gamePlayers[i].cardData);
						}
						showDisplayObject(cardCount[chairViewID], !GameModel.i.gamePlayers[i].isBright);
					}
				}
			}
			else
			{
				tickCount++;
			}
		}
		private function onTimerCountComplete(evt:Event):void
		{
			switch(curState)
			{
				case STATE_FREE: 
				{
					var gameServer:GameServer = GameModel.i.gameServer;
					if(gameServer.isType(GameServer.GAME_GENRE_RALLY))
					{
						curState = STATE_WAIT;
						NetFacade.i.send(UserGroup.MDM_GR_USER, UserGroup.SUB_GR_USER_STANDUP_REQ);
						netRequestRunInfo(GameConst.GAME_EVT_ID_RALLY);
					}
					else
					{
						onLeaveGameHandle(); 
					}
					break;
				}
				case STATE_READY: break;
				case STATE_SENDCARD: break;
				case STATE_CALLLAND: onLandScoreHandle(GameConst.ACTION_PASS);break;
				case STATE_SNATCHLAND: onLandScoreHandle(GameConst.ACTION_PASS);break;
				case STATE_BRIGHTCARD: onBrightCard(255);break;
				case STATE_DOUBLESCORE: onDoubleScore(false);break;
				case STATE_GAME: 
				{
					if(!isLookonMode() && !isAutoPlay && GameModel.i.curUser == this.getMeChairID())
					{
						onUserTrusteeHandle(true);
						var outCardData:Array = GameModel.i.outCardData;
						onAutoOutCardHandle(outCardData);
					}
					break;
				}
				case STATE_GAMEEND: break;
				case STATE_WAIT:break;
			}
			killTimer();
		}
		private function onWaitTimerComplete(evt:Event):void
		{
			WaitPanel.i.show(false);
			WaitPanel.i.removeEventListener(WaitPanel.WAIT_COMPLETE, onWaitTimerComplete);
			WaitPanel.i.removeEventListener(WaitPanel.AWARD_COMPLETE, onAwardTimerComplete);
			WaitPanel.i.removeEventListener(WaitPanel.CONTINUE_GAME, onWaitContinueGame);
			WaitPanel.i.removeEventListener(WaitPanel.EXIT, onWaitExitGame);
			onLeaveGameHandle();
		}
		private function onAwardTimerComplete(evt:Event):void
		{
			
		}
		private function onWaitContinueGame(evt:Event):void
		{
			showDisplayObject(ready[0], true);
			WaitPanel.i.removeEventListener(WaitPanel.WAIT_COMPLETE, onWaitTimerComplete);
			WaitPanel.i.removeEventListener(WaitPanel.AWARD_COMPLETE, onAwardTimerComplete);
			WaitPanel.i.removeEventListener(WaitPanel.CONTINUE_GAME, onWaitContinueGame);
			WaitPanel.i.removeEventListener(WaitPanel.EXIT, onWaitExitGame);
			onGameStartHandle();
		}
		private function onWaitExitGame(evt:Event):void
		{
			WaitPanel.i.removeEventListener(WaitPanel.WAIT_COMPLETE, onWaitTimerComplete);
			WaitPanel.i.removeEventListener(WaitPanel.AWARD_COMPLETE, onAwardTimerComplete);
			WaitPanel.i.removeEventListener(WaitPanel.CONTINUE_GAME, onWaitContinueGame);
			WaitPanel.i.removeEventListener(WaitPanel.EXIT, onWaitExitGame);
			onLeaveGameHandle();
		}
		private function onTimerCount(evt:GlobalEvent):void
		{
			if(evt.data < 6)
			{
				if(curState == STATE_FREE || (GameModel.i.curUser==this.getMeChairID() && !isLookonMode()))
					playSound("GAME_WARN");
			}
			main.timerCount.gotoAndStop(31 - evt.data);
			
		}
		private function onLackPetrolExit(evt:Event):void
		{
			onLeaveGameHandle();
		}
		
//=================================================================================================================================
		
		override protected function netNofityTableStatus(...parms):void
		{
			
		}
		override protected function netNofityUserStatus(...parms):void
		{
			var userStatus:UserStatus = parms[0]._parm as UserStatus;
			if(userStatus.dwUserID == MeInfoModel.i.userInfo.dwUserID)
			{
//				if(userStatus.cbUserStatus == UserStatus.STATE_FREE || userStatus.cbUserStatus == UserStatus.STATE_SIT)
//					btnTrustee.enable = false;
//				else if(userStatus.cbUserStatus == UserStatus.STATE_READY || userStatus.cbUserStatus == UserStatus.STATE_GAME)
//					btnTrustee.enable = true;
				btnTrustee.enable = userStatus.cbUserStatus == UserStatus.STATE_GAME;
			}
			updateUserStatus();
		}
		override protected function netNofityUserScore(...parms):void
		{
			var dwUserID:uint = parms[0]._parm;
			if(MeInfoModel.i.userInfo.dwUserID == dwUserID)
			{
				GlobalPanel.i.updateInfo();
				if(this.getMeChairID() != -1)
					score[getMeViewChairID()].value.text = MeInfoModel.i.userScore.lScore;
			}
		}
		public function netRequestTrustee(chairID:uint, isTrustee:Boolean):void
		{
			isAutoPlay = isTrustee;
			var data:Object = new Object();
			data.chairID =  chairID;
			data.isTrustee = isTrustee;
			NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_TRUSTEE, data);
		}
		
		private function onAutoOutCardHandle(cards:Array):void
		{
			var wMeChairID:uint = getMeViewChairID();
			if (cards.length == 0)
			{
				killTimer();
				this.showDisplayObject(out, false);
				GameModel.i.outCardData = tipsList[0].slice();
				updateOutCardControl(wMeChairID, GameModel.i.outCardData.slice());
				NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_OUT_CART);
				showCardType();
			}
			else if(cards.length == 1 && tipsList.length > 0 && cardControl[wMeChairID].getCardCount()==1)
			{
				killTimer();
				this.showDisplayObject(out, false);
				GameModel.i.outCardData = tipsList[0];
				updateOutCardControl(wMeChairID, GameModel.i.outCardData.slice());
				NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_OUT_CART);
				showCardType();
			}
			else
			{
				onPassCardHandle();
			}
		}
		private function onDoubleScore(isDouble:Boolean):void
		{
			killTimer();
			showDisplayObject(btnDoubleScore, false);
			showDisplayObject(btnNotDoubleScore, false);
			NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_DOUBLE_SCORE, isDouble);
		}
		private function onBrightCard(brightCardTime:uint):void
		{
			showDisplayObject(btnBrightCard, false);
			showDisplayObject(btnNotBrightCard, false);
			NetFacade.i.send(GameGroup.MDM_GF_GAME,GameGroup.SUB_C_BRIGHT, brightCardTime);
			if(curState == STATE_BRIGHTCARD)
			{
				killTimer();
			}
		}
		override protected function netNofitySendCard(...parms):void
		{
			tickCount = 0;
			
			curState = STATE_SENDCARD;
			
			showDisplayObject(ready, false);
			showDisplayObject(btnStart, false);
			showDisplayObject(btnBrightCard, !meIsBright);
			showDisplayObject(tips, false);
			showDisplayObject(baseScore, true);
			baseScore.value = GameModel.i.baseScore;
			baseScore.x = 0;
			doubleScore.x = -5;
			
			killTimer();
			isExitGame = false;
			effectShowCard[0].addEventListener(EffectShowCard.SHOW_CARD, onEffectShowCard);
			var controls:CardControl = null;
			var movieClipList:Array = null;
			var chairView:uint = 0;
			var point:Array = [new Point(480,630),new Point(730,350),new Point(220,350),new Point(490,180)];
			for(var i:uint = 0; i< 3; i++)
			{
				chairView = switchViewChairID(i);
				showDisplayObject(tips[chairView], GameModel.i.gamePlayers[i].isBright);
				controls = cardControl[chairView];
				controls.setBright(i==getMeChairID() || GameModel.i.gamePlayers[i].isBright);
				if(i!=getMeChairID())
				{
					if(chairView == 2)
						controls.setReverse(!GameModel.i.gamePlayers[i].isBright);
				}
				controls.SetCardData(GameModel.i.gamePlayers[i].cardData);
				showDisplayObject(controls, true);
				
				movieClipList = controls.getMovieClipList();
				if(switchViewChairID(i) == 1)
					movieClipList.reverse();
				var effectCard:EffectShowCard = effectShowCard[i] as EffectShowCard;
				effectCard.setCard(movieClipList);
				effectCard.start();
				effectCard.addEventListener(Event.COMPLETE, onSendCardComplete);
			}
			
			backControl.setBright(false);
			backControl.SetCardData(GameModel.i.backCard);
			showDisplayObject(backControl, true);
			showDisplayObject(cardCount, false);
		}
		override protected function netNofityLandScore(...parms):void
		{
			var curViewChairID:uint = switchViewChairID(GameModel.i.curUser);
			var preViewChairID:uint = switchViewChairID(GameModel.i.preUser);
			
			showDisplayObject(tips[curViewChairID], false);
			
			if(GameModel.i.preScorePhase == GameConst.CSD_NORMAL)
			{
				if(GameModel.i.preLandScore == -1)
				{
					showDisplayObject(tips[preViewChairID], true);
					tips[preViewChairID].gotoAndStop(FRAME_NOCALL);
					playSound("GIVE_UP_SCORE");
				}
				else if(GameModel.i.preLandScore == 3)
				{
					showDisplayObject(tips[preViewChairID], true);
					tips[preViewChairID].gotoAndStop(FRAME_CALLLAND);
					updateLandImage(GameModel.i.preUser);
					playSound("CALL_CARD");
				}
			}
			else if(GameModel.i.preScorePhase == GameConst.CSD_SNATCHLAND)
			{
				if(GameModel.i.preLandScore == -1)
				{
					showDisplayObject(tips[preViewChairID], true);
					tips[preViewChairID].gotoAndStop(FRAME_NOGRAB);
					playSound("NOT_SNATCH_LAND");
				}
				else if(GameModel.i.preLandScore == 4)
				{
					showDisplayObject(tips[preViewChairID], true);
					tips[preViewChairID].gotoAndStop(FRAME_GRABLAND);
					updateLandImage(GameModel.i.preUser);
					playSound("SNATCH_LAND");
				}
			}
			
			if(GameModel.i.curScorePhase == GameConst.CSD_BRIGHTCARD)
			{
				showDisplayObject(tips, false);
			}
			
			if (GameModel.i.curScorePhase == GameConst.CSD_NORMAL)
			{
				curState = STATE_CALLLAND;
				showTimer(curViewChairID, GameConst.TIMER_CALLLAND, 1);
				if(GameModel.i.curUser == getMeChairID())
				{
					showDisplayObject(tips[curViewChairID], false);
					showDisplayObject(btnCallLand, true);
					showDisplayObject(btnNotCallLand, true);
					updateTrustee();
				}
			}
			else if (GameModel.i.curScorePhase == GameConst.CSD_SNATCHLAND)
			{
				curState = STATE_SNATCHLAND;
				showTimer(curViewChairID, GameConst.TIMER_SNATCHLAND, 1);
				if(GameModel.i.curUser == getMeChairID())
				{
					showDisplayObject(tips[curViewChairID], false);
					showDisplayObject(btnSnatchLand, true);
					showDisplayObject(btnNotSnatchLand, true);
					updateTrustee();
				}
			}
			else if (GameModel.i.preScorePhase!=GameConst.CSD_BRIGHTCARD && GameModel.i.curScorePhase==GameConst.CSD_BRIGHTCARD)
			{
				curState = STATE_BRIGHTCARD;
				showDisplayObject(tips, false);
				if(!GameModel.i.gamePlayers[getMeChairID()].isBright)
				{
					var meViewChairID:uint = this.getMeViewChairID();
					showTimer(meViewChairID, GameConst.TIMER_BRIGHTCARD, 1);
					showDisplayObject(btnBrightCard, true);
					showDisplayObject(btnNotBrightCard, true);
					updateTrustee();
				}
			}
		}
		override protected function netNofityGameStart(...parms):void
		{
			curState = STATE_GAME;
			mcStart.gotoAndPlay(0);
			this.showDisplayObject(mcStart, true);
			this.showDisplayObject(tips, false);
			this.showDisplayObject(outControl, true);
			showTimer(switchViewChairID(GameModel.i.curUser), GameConst.TIMER_OUTCARD_FIRST, 1);
			var meChairId:uint = getMeChairID();
			var i:uint = 0;
			GameLogic.i.AnalysebCardData(cardControl[0].GetCardData(),analyseResult);
			showCardType();
			if(GameModel.i.curUser == meChairId)
			{
				showDisplayObject(out, true);
				btnPass.enable = false;
				GameLogic.i.serchCardData((cardControl[0] as CardControl).GetCardData(), GameModel.i.outCardData, tipsList, analyseResult);
			}
			if(isAutoPlay && GameModel.i.landlordUser == this.getMeChairID())
				trusteeOutCard();
			for(i = 0; i < 3;i++)
				(outControl[i] as CardControl).SetCardData(null);
			GameModel.i.outCardData.length = 0;
			curTipsIndex = -1;
			
			SelectPanel.i.select = true;
			SelectPanel.i.selRectange = new Rectangle(79, 519, 651, 129);
			(cardControl[0] as CardControl).setRectSelect(true);
			for(i = 0; i < cardtype.length;i++)
				cardtype[i].btn.visible = true;
			updateLandImage(GameModel.i.landlordUser);
		}
		override protected function netNofityOutCard(...parms):void
		{
			//界面设置
			var outCardUser:uint = GameModel.i.outCardUser;
			var wOutViewChairID:uint=switchViewChairID(outCardUser);
			var curViewChairID:uint = switchViewChairID(GameModel.i.curUser);
			//出牌设置
			if ((isLookonMode()==true)||(getMeChairID()!=outCardUser))
			{
				this.updateOutCardControl(wOutViewChairID, GameModel.i.outCardData.slice());
			}
			this.updateCardCount();
			var bWarning:Boolean = false;
			var cardCount:uint = (cardControl[switchViewChairID(GameModel.i.outCardUser)] as CardControl).GetCardCount();
			if(cardCount <= 2 && GameModel.i.outCardUser != getMeChairID() && !(GameModel.i.gamePlayers[GameModel.i.outCardUser].isAlarm))
			{
				playSound("WARMING_CARD");
				var mc:MovieClip = alarm[switchViewChairID(GameModel.i.outCardUser)];
				showDisplayObject(mc, true);
				mc.gotoAndPlay(0);
				bWarning = true;
				GameModel.i.gamePlayers[GameModel.i.outCardUser].isAlarm = true;
			}
			
			var cardType:uint = GameLogic.i.GetCardType(GameModel.i.outCardData);
			switch(cardType)
			{
				case GameLogic.CT_BOMB_CARD: 
					if(!bWarning)
						playSound("BOMB"); 
					mcBomb.gotoAndPlay(0);
					this.showDisplayObject(mcBomb, true);break;
				case GameLogic.CT_MISSILE_CARD: 
					if(!bWarning)
						playSound("BOMB"); 
					mcBomb.gotoAndPlay(0);
					this.showDisplayObject(mcBomb, true);break;
				case GameLogic.CT_SINGLE_LINE:
					if(!bWarning)
						playSound("OUT_CARD");
					mcShunzi.gotoAndPlay(0);
					this.showDisplayObject(mcShunzi, true); break;
				case GameLogic.CT_DOUBLE_LINE:
					if(!bWarning)
						playSound("OUT_CARD");
					mcShuangShun.gotoAndPlay(0);
					this.showDisplayObject(mcShuangShun, true); break;
				default: 
					if(!bWarning)
						playSound("OUT_CARD"); break;
			}
			
			if(passCount >= 2)
				showDisplayObject(tips, false);
			
			var i:uint = 0;
			passCount = 0;
			if(GameModel.i.curUser == GameModel.i.outCardUser)
			{
				for(i = 0; i < Define.GAME_PLAYER; i++)
				{
					if(i != GameModel.i.outCardUser)
					{
						var viewChairID:uint = switchViewChairID(i);
						outControl[viewChairID].SetCardData(null);
						tips[viewChairID].gotoAndStop(FRAME_NOOUT);
						showDisplayObject(tips[viewChairID], true);
					}
				}
				if(GameModel.i.curUser == this.getMeChairID())
				{
					GameModel.i.outCardData.length = 0;
					killTimer();
					var outTime:Number = 2000;
					handleQueue.add({delay:outTime, handle:outCard});
					handleQueue.reset();
					handleQueue.start();
				}
				passCount = 2;
				return;
			}
			
			if(GameModel.i.curUser != GameConst.INVALID_CHAIR && GameModel.i.curUser != GameModel.i.outCardUser)
			{
				viewChairID = switchViewChairID(GameModel.i.curUser);
				outControl[viewChairID].SetCardData(null);
			}
			
			if (!isLookonMode() &&(GameModel.i.curUser==getMeChairID()))
			{
				showDisplayObject(out, true);
				btnPass.enable = true;
				if(isAutoPlay)
				{
					if((cardControl[0] as CardControl).GetCardCount() == 1)
						GameLogic.i.serchCardData((cardControl[0] as CardControl).GetCardData(), GameModel.i.outCardData, tipsList, analyseResult);
					trusteeOutCard();
				}
				else
				{
					curTipsIndex = -1;
					GameLogic.i.serchCardData((cardControl[0] as CardControl).GetCardData(), GameModel.i.outCardData, tipsList, analyseResult);
					var wMeChairID:uint = this.switchViewChairID(getMeChairID());
					if(tipsList.length > 0)
					{
						curTipsIndex = 0;
						cardControl[wMeChairID].shootCardByData(tipsList[curTipsIndex]);
					}
				}
			}
			showTimer(curViewChairID, GameConst.TIMER_OUTCARD, 1);
			showDisplayObject(tips[curViewChairID], false);
		}
		private function showCardType():void
		{
			GameLogic.i.AnalysebCardData(cardControl[getMeViewChairID()].GetCardData(), analyseResult);
			getCardDataByType();
			for(var i:uint = 0; i < cardtype.length; i++)
			{
				var isClick:Boolean = cardtype[i].result && cardtype[i].result.length!=0;
				cardtype[i].btn.enable = isClick;
				cardtype[i].index = -1;
			}
		}
		private function getCardDataByType():void
		{
			for(var i:uint = 0; i < cardtype.length; i++)
			{
				cardtype[i].result = getData(cardtype[i].type);
			}
			function getData(cardType:uint):Array
			{
				var retArr:Array = [];
				var cardData:Array = null;
				var i:uint = 0;
				switch(cardType)
				{
					case GameLogic.CT_SINGLE_LINE:
						return analyseResult.cbSignedLineCardData;
					case GameLogic.CT_DOUBLE_LINE:
						return analyseResult.cbDoubleLineCardData;
					case GameLogic.CT_MISSILE_CARD:
						return analyseResult.cbMissileCardData;
					case GameLogic.CT_BOMB_CARD:
						return analyseResult.cbFourCardData;
					case GameLogic.CT_THREE_LINE:
						return analyseResult.cbAircraftCardData;
					case GameLogic.CT_DOUBLE:
						return analyseResult.cbDoubleCardData;
					case GameLogic.CT_THREE:
						return analyseResult.cbThreeCardData;
				}
				return null;
			}
		}
		private function outCard():void
		{
			for(var j:uint = 0; j < Define.GAME_PLAYER; j++)
			{
				var view:uint = switchViewChairID(j);
				showDisplayObject(tips[view], false);
				outControl[view].SetCardData(null);
			}
			if(GameModel.i.curUser == this.getMeChairID())
			{
				showDisplayObject(out, true);
				btnPass.enable = false;
				if(isAutoPlay)
					this.trusteeOutCard();
				else
				{
					GameLogic.i.serchCardData((cardControl[0] as CardControl).GetCardData(), GameModel.i.outCardData, tipsList, analyseResult);
				}
			}
			var curViewChairID:uint = switchViewChairID(GameModel.i.curUser);
			showTimer(curViewChairID, GameConst.TIMER_OUTCARD, 1);
		}
		private function trusteeOutCard():void
		{
			var outTime:Number = 1000;
			handleQueue.add({delay:outTime, handle:onAutoOutCardHandle, parm:[GameModel.i.outCardData]});
			handleQueue.reset();
			handleQueue.start();
		}
		private function trusteeCallLand():void
		{
			var outTime:Number = RandomUtil.randomRange(1000, 2000);
			handleQueue.add({delay:outTime, handle:onLandScoreHandle, parm:[GameConst.ACTION_PASS]});
			handleQueue.reset();
			handleQueue.start();
		}
		private function trusteeGrabLand():void
		{
			var outTime:Number = RandomUtil.randomRange(1000, 2000);
			handleQueue.add({delay:outTime, handle:onLandScoreHandle, parm:[GameConst.ACTION_PASS]});
			handleQueue.reset();
			handleQueue.start();
		}
		private function trusteeBrightCard():void
		{
			var outTime:Number = RandomUtil.randomRange(1000, 2000);
			handleQueue.add({delay:outTime, handle:onBrightCard, parm:[255]});
			handleQueue.reset();
			handleQueue.start();
		}
		private function trusteeDoubleScore():void
		{
			var outTime:Number = RandomUtil.randomRange(1000, 2000);
			handleQueue.add({delay:outTime, handle:onDoubleScore, parm:[false]});
			handleQueue.reset();
			handleQueue.start();
		}
		override protected function netNofityPassCard(...parms):void
		{
			passCount++;
			
			var wViewChairID:uint=this.switchViewChairID(GameModel.i.curUser);
			outControl[wViewChairID].SetCardData(null);
			showDisplayObject(tips[wViewChairID], false);
			showTimer(wViewChairID, GameConst.TIMER_OUTCARD, 1);
			
			var passViewChairID:uint = switchViewChairID(GameModel.i.passUser);
			tips[passViewChairID].gotoAndStop(FRAME_NOOUT);
			showDisplayObject(tips[passViewChairID], true);
			
			if(passCount >= 2)
				GameModel.i.outCardData.length = 0;
			
			if(GameModel.i.outCardUser==getMeChairID())
				this.showDisplayObject(out, false);
			if (!isLookonMode() && GameModel.i.curUser==getMeChairID() && GameModel.i.passUser!=getMeChairID())
			{
				btnPass.enable = passCount < 2;
				this.showDisplayObject(out, true);
				if(isAutoPlay)
				{
					GameLogic.i.serchCardData((cardControl[0] as CardControl).GetCardData(), GameModel.i.outCardData, tipsList, analyseResult);
					trusteeOutCard();
				}
				else 
				{
					curTipsIndex = -1;
					GameLogic.i.serchCardData((cardControl[0] as CardControl).GetCardData(), GameModel.i.outCardData, tipsList, analyseResult);
					if(tipsList.length > 0 && passCount < 2)
					{
						curTipsIndex = 0;
						cardControl[getMeViewChairID()].shootCardByData(tipsList[curTipsIndex]);
					}
				}
			}
			
			playSound("PASS_CARD");
		}
		override protected function netNofityGameEnd(...parms):void
		{
			curState = STATE_FREE;
			if(!isExitGame)
			{
				var meScore:int = GameModel.i.gameScore[getMeChairID()];
				if (meScore > 0) 
					playSound("GAME_WIN");
				else if (meScore < 0) 
					playSound("GAME_LOST");
				else 
					playSound("GAME_END");
				gameResult.updateData();
				gameResult.show(true);
				ChessLobby.dialog.addChild(btnStart);
				ChessLobby.dialog.addChild(btnBrightStart);
				btnStart.y = 470;
				btnBrightStart.y = 470;
				showDisplayObject(btnStart, true);
				showDisplayObject(btnBrightStart, true);
				showDisplayObject(tips, false);
				showDisplayObject(info, false);
				showDisplayObject(btnOutCard, false);
				showDisplayObject(btnTips, false);
				showDisplayObject(btnPass, false);
				showDisplayObject(btnCannelTrustee, false);
				showDisplayObject(mcTrustee, false);
				showDisplayObject(mcShunzi, false);
				showDisplayObject(mcShuangShun, false);
				showDisplayObject(mcBomb, false);
				showDisplayObject(mcStart, false);
				showDisplayObject(imgLand, false);
				showDisplayObject(btnRestart, false);
				showDisplayObject(btnChangeTable, false);
				showDisplayObject(btnCallLand, false);
				showDisplayObject(btnNotCallLand, false);
				showDisplayObject(btnSnatchLand, false);
				showDisplayObject(btnNotSnatchLand, false);
				showDisplayObject(btnDoubleScore, false);
				showDisplayObject(btnNotDoubleScore, false);
				showDisplayObject(btnBrightCard, false);
				showDisplayObject(btnNotBrightCard, false);
				showDisplayObject(alarm, false);
				showDisplayObject(baseScore, false);
				showDisplayObject(doubleScore, false);
				showDisplayObject(cardCount, false);
				
				for(var i:uint = 0; i < Define.GAME_PLAYER; i++)
				{
					var viewChairID:uint = switchViewChairID(i);
					
					if(viewChairID != 0)
					{
						if(!GameModel.i.gamePlayers[i].isBright)
						{
							cardControl[viewChairID].setBright(true);
							if(viewChairID == 2)
								cardControl[viewChairID].setReverse(false);	
							cardControl[viewChairID].SetCardData(cardControl[viewChairID].GetCardData());
						}
					}
					GameModel.i.gamePlayers[i].isBright = false;
				}
				onUserTrusteeHandle(false);
				showTimer(0, GameConst.TIMER_FREE, 1);
				SelectPanel.i.select = false;
				for(i = 0; i < cardtype.length; i++)
					cardtype[i].btn.visible = false;
				meIsBright = false;
				gameInit();
				handleQueue.add({delay:5000, handle:onGameResultClose});
				handleQueue.reset();
				handleQueue.start();
				
				printScore();
				
				Memory.gc();
			}
		}
		private function onGameResultClose(evt:Event = null):void
		{
			btnStart.y = 389;
			btnBrightStart.y = 389;
			main.addChild(btnStart);
			main.addChild(btnBrightStart);
			gameResult.show(false);
			gameResult.removeEventListener(GameResult.DLG_CLOSE, onGameResultClose);
		}
		override protected function netNofityBrightStart(...parms):void
		{
			var obj:Object = parms[0]._parm;
			onUserBrightCardHandle(obj.brightUser, obj.isBright);
		}
		override protected function netNofityBrightCard(...parms):void
		{
			onUserBrightCardHandle(GameModel.i.brightUser, GameModel.i.gamePlayers[GameModel.i.brightUser].isBright);
		}
		override protected function netNofityPlayerTrustee(...parms):void
		{
			
		}
		override protected function netNofityDoubleScore(...parms):void
		{
			curState = STATE_DOUBLESCORE;
			var bAllowDouble:Boolean = GameModel.i.allowDouble;
			btnDoubleScore.enable = bAllowDouble;
			showDisplayObject(btnDoubleScore, true);
			showDisplayObject(btnNotDoubleScore, true);
			showDisplayObject(btnBrightCard, false);
			showDisplayObject(btnNotBrightCard, false);
			showDisplayObject(tips, false);
			backControl.setBright(true);
			backControl.SetCardData(GameModel.i.backCard);
			var wLandUser:uint = GameModel.i.landlordUser;
			var userCard:Array = GameModel.i.gamePlayers[wLandUser].cardData;
			var backCard:Array = GameModel.i.backCard;
			var gamePlay:Array = GameModel.i.gamePlayers;
			
			for(var i:uint = 0; i < backCard.length; i++)
				userCard.push(backCard[i]);
			
			cardControl[switchViewChairID(wLandUser)].SetCardData(userCard);
			updateLandImage(GameModel.i.landlordUser);
			showTimer(switchViewChairID(getMeChairID()), GameConst.TIMER_DOUBLESCORE, 1);
			
			updateTrustee();
		}
		override protected function netNofityUserDouble(...parms):void
		{
			var doubleViewChairID:uint = switchViewChairID(GameModel.i.doubleUser);
			this.showDisplayObject(tips[doubleViewChairID], true);
			tips[doubleViewChairID].gotoAndStop(GameModel.i.isDouble?FRAME_DOUBLE:FRAME_NODOUBLE);
		}
		override protected function netNofityMultiple(...parms):void
		{
			var isReady:Boolean = curState != STATE_FREE && curState != STATE_READY;
			setBrightTime(GameModel.i.curBrightTime);
			if(!isReady) doubleScore.x = -55;
		}
		private function netRequestRunInfo(id:uint):void
		{
			NetFacade.i.send(RoomGroup.MDM_GR_SERVER_INFO, RoomGroup.SUB_GR_RUNINFO_REQ, id);
		}
		override protected function netNotifyUserSupplyApplySuc(...parms):void
		{
			LackPetrolPanel.i.busy = false;
			LackPetrolPanel.i.show(false);
			FloatText.i.start("加油成功，重返赛场！");
			showDisplayObject(btnStart, true);
			showDisplayObject(btnBrightStart, true);
			curState = STATE_FREE;
			showTimer(0, GameConst.TIMER_FREE, 1);
			onGameResultClose();
		}
		override protected function netReplyRunInfo(...parms):void
		{
			onUserWaitHandle();
		}
		override protected function netNotifyUserSupplyNeed(...parms):void
		{
			onUserLackPetrolHandle();
		}
		override public function netNotifyUserMoneyLess(...parms):void
		{
			killTimer();
			handleQueue.clear();
			RechargePanel.i.show(true);
			RechargePanel.i.addEventListener(RechargePanel.EXIT, onRechargePanelExit);
			RechargePanel.i.addEventListener(RechargePanel.ADDMONEY, onRechargePanelAddMoney);
			ExitPanel.i.removeEventListener(ExitPanel.OK, onExitPanelOK);
			ExitPanel.i.removeEventListener(ExitPanel.CANSEL, onExitPanelClose);
		}
		override public function netNotifyRewardMessage(...parms):void
		{
			isClickChest = false;
			btnChest.gotoAndPlay(1);
			showDisplayObject(btnChest, true);
		}
		
//=================================================================================================================================
		
		private function onRechargePanelExit(evt:Event):void
		{
			RechargePanel.i.removeEventListener(RechargePanel.EXIT, onRechargePanelExit);
			RechargePanel.i.removeEventListener(RechargePanel.ADDMONEY, onRechargePanelAddMoney);
			onLeaveGameHandle();
		}
		private function onRechargePanelAddMoney(evt:Event):void
		{
			RechargePanel.i.removeEventListener(RechargePanel.EXIT, onRechargePanelExit);
			RechargePanel.i.removeEventListener(RechargePanel.ADDMONEY, onRechargePanelAddMoney);
			onLeaveGameHandle();
		}
		private function onUserBrightCardHandle(brightUser:uint, isBright:Boolean):void
		{
			var viewChairID:uint = switchViewChairID(brightUser);
			showDisplayObject(tips[viewChairID], true);
			tips[viewChairID].gotoAndStop(isBright ? FRAME_BRIGHT : FRAME_NOBRIGHT);
			if(isBright) 
			{
				playSound("BRIGHT_CARD");
				showDisplayObject(ready[viewChairID], false);
			}
			if(curState == STATE_BRIGHTCARD)
			{
				var chairViewID:uint = switchViewChairID(brightUser);
				if(chairViewID != this.getMeViewChairID() && GameModel.i.gamePlayers[brightUser].isBright)
				{
					if(chairViewID == 2)
						cardControl[chairViewID].setReverse(false);
					cardControl[chairViewID].setBright(GameModel.i.gamePlayers[brightUser].isBright);
					cardControl[chairViewID].SetCardData(GameModel.i.gamePlayers[brightUser].cardData);
					showDisplayObject(cardCount[chairViewID], !GameModel.i.gamePlayers[brightUser].isBright);
				}
			}
		}
		private function onUserChatHandle(userChat:UserChat):void
		{
			var userStatus:UserStatus = GameModel.i.getUserStatusByUserID(userChat.dwSendUserID);
			if(userStatus != null)
			{
				var viewChairID:uint = this.switchViewChairID(userStatus.wChairID);
				showDisplayObject((chatBubble[viewChairID] as GameChat), true);
				(chatBubble[viewChairID] as GameChat).appendRichText(userChat.szChatMessage);
			}
		}
		private function onUserTrusteeHandle(trustee:Boolean):void
		{
			if(isAutoPlay == trustee) return;
			isAutoPlay = trustee;
			handleQueue.clear();
			btnTrustee.enable = !trustee;
			this.showDisplayObject(btnCannelTrustee, trustee);
			this.showDisplayObject(mcTrustee, trustee);
			this.netRequestTrustee(getMeChairID(), trustee);
		}
		private function onLandScoreHandle(landScore:uint):void
		{
			if(GameModel.i.curUser != this.getMeChairID())
				return;
			killTimer();
			showDisplayObject(btnBrightCard, false);
			showDisplayObject(btnNotBrightCard, false);
			showDisplayObject(btnSnatchLand, false);
			showDisplayObject(btnNotSnatchLand, false);
			showDisplayObject(btnCallLand, false);
			showDisplayObject(btnNotCallLand, false);
			
			NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_LAND_SCORE, landScore);
		}
		private function onPassCardHandle():void
		{
			if(GameModel.i.curUser != this.getMeChairID())
				return;
			killTimer();
			NetFacade.i.send(GameGroup.MDM_GF_GAME, GameGroup.SUB_C_PASS_CARD);
			cardControl[this.switchViewChairID(getMeChairID())].ShootAllCard(false);
			this.showDisplayObject(out, false);
		}
		private function onUserLackPetrolHandle():void
		{
			handleQueue.clear();
			killTimer();
			LackPetrolPanel.i.updateData();
			LackPetrolPanel.i.show(true);
			LackPetrolPanel.i.addEventListener(LackPetrolPanel.SELECT_ITEM, onLackPetrolAddPrtrol);
			LackPetrolPanel.i.addEventListener(LackPetrolPanel.EXIT, onLackPetrolExit);
		}
		private function onGameStartHandle():void
		{
			curState = STATE_READY;
			killTimer();
			showDisplayObject(btnStart, false);
			showDisplayObject(btnBrightStart, false);
			showDisplayObject(cardControl, false);
			showDisplayObject(outControl, false);
			showDisplayObject(backControl, false);
			gameResult.show(false);
			var evt:GlobalEvent = new GlobalEvent(GlobalEvent.GLOBAL_USERREADY);
			evt.view = this;
			evt.dispatch();
		}
		private function onUserWaitHandle():void
		{
			curState = STATE_WAIT;
			WaitPanel.i.updateData();
			WaitPanel.i.show(true);
			WaitPanel.i.addEventListener(WaitPanel.WAIT_COMPLETE, onWaitTimerComplete);
			WaitPanel.i.addEventListener(WaitPanel.AWARD_COMPLETE, onAwardTimerComplete);
			WaitPanel.i.addEventListener(WaitPanel.CONTINUE_GAME, onWaitContinueGame);
			WaitPanel.i.addEventListener(WaitPanel.EXIT, onWaitExitGame);
			ExitPanel.i.removeEventListener(ExitPanel.OK, onExitPanelOK);
			ExitPanel.i.removeEventListener(ExitPanel.CANSEL, onExitPanelClose);
		}
		private function onLeaveGameHandle(parm:* = null):void
		{
			isExitGame = true;
			gameResult.show(false);
			var gameServer:GameServer = GameModel.i.gameServer;
			if(gameServer.isType(GameServer.GAME_GENRE_RALLY))
			{
				if(curState != STATE_FREE && curState != STATE_READY && curState != STATE_WAIT)
				{
					if(GameModel.i.lostScore != 0)
						MeInfoModel.i.userScore.lScore -= GameModel.i.lostScore;
					if(GameModel.i.lostGold != 0)
						MeInfoModel.i.userScore.lGoldScore -= GameModel.i.lostGold;
				}
				MeInfoModel.i.userScore.lGoldScore += MeInfoModel.i.userScore.lMoneyGold;
				GlobalPanel.i.updateInfo();
			}
			
			NetFacade.i.send(UserGroup.MDM_GR_USER, isMustEixt ? UserGroup.SUB_GR_USER_LEFT_GAME_REQ : UserGroup.SUB_GR_USER_LEFT_ROOM_REQ);
			if(gameServer.isType(GameServer.GAME_GENRE_SCORE))
			{
				MeInfoModel.i.serverInfo = null;
				changeState(L.L_SelTable);
			}
			else if(gameServer.isType(GameServer.GAME_GENRE_ANTICHEAT) || gameServer.isType(GameServer.GAME_GENRE_RALLY))
			{
				changeState(L.L_Lobby);
			}
		}
		private function gameInit():void
		{
			GameModel.i.lostScore = 0;
			GameModel.i.lostGold = 0;
		}
		private function printScore():void
		{
			var score:Array = [];
			var str:String;
			for(var i:uint = 0; i < 3; i++)
			{
				str = GameModel.i.gameScore[i].toString();
				if(GameModel.i.gameScore[i] > 0)
				{
					str = "+" + str;
				}
				else if(GameModel.i.gameScore[i] == 0)
				{
					str = "  " + str;
				}
				else
				{
					str = "- " + str.substr(1);
				}
				score[i] = str;
			}
			str = "<b><font face='verdana' color='#a97fe8' size='12' leading='5' >[成绩]: </font> </b>"
				+ "<font face='verdana' color='#7a5dcb' size='12' leading='5' >"+
				"总第"+(GameModel.i.tableInfo.wTableID+1)+"桌，成绩如下：\n"+
				"<textformat tabstops='[150]'>";
			str += 	"          " + GameModel.i.userAccount[0]+":"+"\t"+"\t"+score[0]+"\n"+
					"          " + GameModel.i.userAccount[1]+":"+"\t"+"\t"+score[1]+"\n"+
					"          " + GameModel.i.userAccount[2]+":"+"\t"+"\t"+score[2]+ "</textformat>" + "</font>";
			OutputPanel.i.outMessage(str);
		}
	}
}